
<!doctype>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>一码通网上商城</title>
<meta name="keywords" content="一码通网上商城" />
<meta name="description" content="一码通网上商城" />
<style type="text/css">
.nc-appbar-tabs a.compare { display: none !important;}
</style>
<link rel="stylesheet" href="../css/reset.css">
<link rel="stylesheet" href="../css/common.css">
<link href="http://beian.80wlkj.com/shop/templates/default/css/base.css" rel="stylesheet" type="text/css">
<link href="http://beian.80wlkj.com/shop/templates/default/css/home_cart.css" rel="stylesheet" type="text/css">
<link href="http://beian.80wlkj.com/shop/resource/font/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
<link href="http://beian.80wlkj.com/shop/templates/default/css/home_header.css" rel="stylesheet" type="text/css">
<!--[if IE 7]>
  <link rel="stylesheet" href="http://beian.80wlkj.com/shop/resource/font/font-awesome/css/font-awesome-ie7.min.css">
<![endif]-->
<script src="http://beian.80wlkj.com/data/resource/js/jquery.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/storage.js"></script>
<script src="http://beian.80wlkj.com/data/resource/js/common.js"></script>
<script src="http://beian.80wlkj.com/data/resource/js/jquery-ui/jquery.ui.js"></script>
<script src="http://beian.80wlkj.com/data/resource/js/jquery.validation.min.js"></script>
<script src="http://beian.80wlkj.com/data/resource/js/jquery.poshytip.min.js"></script>
<script type="text/javascript" src="http://beian.80wlkj.com/data/resource/js/dialog/dialog.js" id="dialog_js" charset="utf-8"></script>
<style>
	input[type=text], input[type=password], input.text, input.password{
		text-align:center;
	}
</style>
<!-- <script src="http://beian.80wlkj.com/data/resource/js/goods_cart.js"></script> -->

<!--[if lt IE 9]>
      <script src="http://beian.80wlkj.com/data/resource/js/html5shiv.js"></script>
      <script src="http://beian.80wlkj.com/data/resource/js/respond.min.js"></script>
<![endif]-->
<!--[if IE 6]>
<script src="http://beian.80wlkj.com/data/resource/js/IE6_PNG.js"></script>
<script>
DD_belatedPNG.fix('.pngFix');
</script>
<script>
// <![CDATA[
if((window.navigator.appName.toUpperCase().indexOf("MICROSOFT")>=0)&&(document.execCommand))
try{
document.execCommand("BackgroundImageCache", false, true);
   }
catch(e){}
// ]]>
</script>
<![endif]-->
</head>
<body>

<div class="public-top-layout w">
<div class="topbar wrapper">
<div class="user-entry">
您好 <span>
<span id="username"></span>
</span> ，欢迎来到 <a href="" title="首页" alt="首页"><span>一码通网上商城</span></a><span><span id="loginIn">[登录]</span> </span><span><span id="register">[注册]</span> </span> <span><span id="loginOut">[退出]</span> </span>
</div>
<div class="quick-menu">
<dl>
<dt><a href="http://beian.80wlkj.com/shop/index.php?act=show_joinin&op=index" title="免费开店">免费开店</a><i></i></dt>
<dd>
<ul>
<li><a href="http://beian.80wlkj.com/shop/index.php?act=show_joinin&op=index" title="招商入驻">招商入驻</a></li>
<li><a href="http://beian.80wlkj.com/shop/index.php?act=seller_login&op=show_login" target="_blank" title="登录商家管理中心">商家登录</a></li>
</ul>
</dd>
 </dl>
<dl>
<dt><a href="../view/orderList.html?act=member_order">我的订单</a><i></i></dt>
<dd>
<ul>
<li><a href="../view/orderList.html?act=member_order&state_type=state_new">待付款订单</a></li>
<li><a href="../view/orderList.html?act=member_order&state_type=state_send">待确认收货</a></li>
<li><a href="../view/orderList.html?act=member_order&state_type=state_noeval">待评价交易</a></li>
</ul>
</dd>
</dl>
</div>
</div>
</div>

<div class="header-wrap">
<header class="public-head-layout wrapper" style="width:1000px;">
<h1 class="site-logo">
	<a href="" style="display:block;width:60%;margin:0 auto;"><img src="../imgs/index/logo.png" class="pngFix"></a>
</h1>
<ul class="ncc-flow">
<li class="current"><i class="step1"></i>
<p>我的购物车</p>
<sub></sub>
<div class="hr"></div>
</li>
<li class=""><i class="step2"></i>
<p>填写核对购物信息</p>
<sub></sub>
<div class="hr"></div>
</li>
<li class=""><i class="step3"></i>
<p>支付提交</p>
<sub></sub>
<div class="hr"></div>
</li>
<li class=""><i class="step4"></i>
<p>订单完成</p>
<sub></sub>
<div class="hr"></div>
</li>
</ul>
</header>
</div>







<div class="ncc-wrapper">
<style>
.ncc-table-style tbody tr.item_disabled td {
	background: none repeat scroll 0 0 #F9F9F9;
	height: 30px;
	padding: 10px 0;
	text-align: center;
}
</style>
<div class="ncc-main">
<div class="ncc-title">
<h3>我的购物车</h3>
<h5>查看购物车商品清单，增加减少商品数量，并勾选想要的商品进入下一步操作。</h5>
</div>
<form action="http://beian.80wlkj.com/shop/index.php?act=buy&op=buy_step1" method="POST" id="form_buy" name="form_buy">
<input type="hidden" value="1" name="ifcart">
<table class="ncc-table-style" nc_type="table_cart">
<thead>
<tr>
<th class="w50"><label>
<input type="checkbox" checked value="1" id="selectAll">
全选</label></th>
<th></th>
<th>商品</th>
<th class="w120">单价(元)</th>
<th class="w120">数量</th>
<th class="w120">小计(元)</th>
<th class="w80">操作</th>
</tr>
</thead>
<tbody>

</tbody>
<tfoot>
<tr>
<td colspan="20"><div class="ncc-all-account">商品总价（不含运费）<em id="cartTotal"></em>元</div></td>
</tr>
</tfoot>
</table>
</form>
<div class="ncc-bottom"><a id="next_submit" href="javascript:void(0)" class="ncc-btn ncc-btn-acidblue fr" onclick="_submit()">下一步，填写核对购物信息</a></div>
</div>
</div>

<div class="footer">
    <ul class="server">
        <li>
            <img src="../imgs/index/01.png">
        </li>
        <li>
            <img src="../imgs/index/02.png">
        </li>
        <li>
            <img src="../imgs/index/03.png">
        </li>
        <li>
            <img src="../imgs/index/04.png">
        </li>
    </ul>
    <ul class="firmInfo">
        <img class="firmInfo__logo" src="../imgs/index/logo.png">
        <div class="firmInfo__text">
            <div style="font-size:14px;color:#666;line-height:30px;">
                公司电话：
            </div>
            <div class="firmPhone">
                400-100-0000
            </div>
            <div class="firmArea">
                公司地址：杭州市萧山区金城路358号蓝爵国际写字楼
            </div>
        </div>
        <div class="firmInfo__QRCode">
            <img src="../imgs/index/logo.png">
            <p>了解更多</p>
        </div>
        
    </ul>
</div>

<script type="text/javascript" src="http://beian.80wlkj.com/data/resource/js/jquery.cookie.js"></script>
<link href="http://beian.80wlkj.com/data/resource/js/perfect-scrollbar.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://beian.80wlkj.com/data/resource/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="http://beian.80wlkj.com/data/resource/js/qtip/jquery.qtip.min.js"></script>
<link href="http://beian.80wlkj.com/data/resource/js/qtip/jquery.qtip.min.css" rel="stylesheet" type="text/css">

<script src="http://beian.80wlkj.com/shop/resource/js/compare.js"></script>
<script type="text/javascript">
$(function(){
	// Membership card
	$('[nctype="mcard"]').membershipCard({type:'shop'});
});
</script>
<script>
//提示信息
$('.tip').poshytip({
	className: 'tip-yellowsimple',
	showOn: 'hover',
	alignTo: 'target',
	alignX: 'center',
	alignY: 'top',
	offsetX: 0,
	offsetY: 5,
	allowTipHover: false
});
</script>
<script type="text/javascript">
$(function() {
	$(".quick-menu dl").hover(function() {
		$(this).addClass("hover");
	},
	function() {
		$(this).removeClass("hover");
	});
});
</script>
<script type="text/javascript">
	$(function(){
		var username = storage.getStorage('username')||'';
		console.log(username);
		$('#username').html(username);
		if(!username){
			$('#loginIn').show();
			$('#register').show();
			$('#loginOut').hide();
		}else{
			$('#loginIn').hide();
			$('#register').hide();
			$('#loginOut').show();
		}
		$('#loginIn').click(function(){
			window.location.href = "./login.html"
		})
		$('#register').click(function(){
			window.location.href = "./register.html"
		})
		$('#loginOut').click(function(){
			storage.storageClear();
			window.location.href = "./login.html"
		})
		$('.goodsList ul li').click(function(){
			var href = './goodsDetail.html?id=' + this.id;
			window.location.href = href;
		})
		console.log(getQueryString('id'));
		$(".quick-menu dl").hover(function() {
        $(this).addClass("hover");
        },
         function() {
         $(this).removeClass("hover");
         });
	})
</script>
<script type="text/javascript">
	$(function(){
		_init();
		check();
	})
	function check(){
		$('#selectAll').change(function(){
			_shopsInfo = [];
			if ($('#selectAll').attr('checked')) {
				_shopsList[0].shopGoods.forEach(function(item,index){
				_shopsInfo.push(item.goodsInfo);
			    })
				$('.shop-list input').prop("checked","checked");
				$('.shop-list').each(function(index,item){
					$('#cartTotal').html(parseFloat(Number($('#cartTotal').html()) + Number($(item).find('.xiaoji').html())).toFixed(2));
				})
				}else{
			  $('.shop-list input').removeAttr("checked");
			  $('#cartTotal').html('0.00');
			}
		})
	}
	function decrease_quantity(self){
		$(self).siblings('input').val(Number($(self).siblings('input').val())-1);
		if ($(self).siblings('input').val()<=1) {
		    $(self).siblings('input').val(1);
		}
		var amount = $(self).siblings('input').val();
		changeCartNum(self,amount);
	}
	function add_quantity(self){
		
		$(self).siblings('input').val(Number($(self).siblings('input').val())+1);
		
		if ($(self).siblings('input').val()>=$(self).siblings('input').data().stock) {
		    $(self).siblings('input').val($(self).siblings('input').data().stock) ;
		}
		var amount = $(self).siblings('input').val();
		changeCartNum(self,amount);
	}
	function change_quantity(self){
		if($(self).val()<=1){
			$(self).val(1); 
		}else if($(self).val() >= $(self).data().stock){
			$(self).val($(self).data().stock);
		}
		var amount = $(self).val();
		changeCartNum(self,amount);
	}
	function changeCartNum(self,amount){
		var cartId = $(self).parents('.shop-list').data().cartid;
		console.log(cartId);
		var url = 'http://192.168.0.120:8080/ymshoping/goodsCar?token='+storage.getStorage('token')+'&goodsCarId='+cartId+'&amount='+amount;
		 $.ajax({
                url:url,
                dataType:'jsonp',
                jsonp:'callback',//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
                jsonpCallback:"success_jsonpCallback",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
                contentType: 'application/json; charset=utf-8',
                success:function(res){
                    if(res.code == 0){
                       console.log(res);
                       var shopsList = res.shopsList;
                       var goodsList = '';
                       var cartList = '';
                       _shopsInfo = [];
                       shopsList.forEach(function(item,index){
                       	 item.shopGoods.forEach(function(val,idx){
                       	 	goodsList += '<tr class="shop-list" data-cartid="'+val.goodsCarId+'"><td><input type="checkbox" checked></td><td class="w60"><a href="" target="_blank" class="ncc-goods-thumb"><img src="http://192.168.0.120:8080/ymshoping/pic?picId='+val.picId+'"alt="'+val.goodsName+'" /></a></td><td class="tl"><dl class="ncc-goods-info"><dt><a href="http://beian.80wlkj.com/shop/index.php?act=goods&op=index&goods_id=52" target="_blank">'+val.goodsName+'</a></dt></dl></td><td class="w120"><em id="item1_price">'+parseFloat(val.mall).toFixed(2)+'</em></td><td class="w120 ws0"><a href="JavaScript:void(0);" onclick="decrease_quantity(this);" title="减少商品件数" class="add-substract-key tip minuBtn">-</a><input value="'+(val.amount || 1)+'" orig="1" changed="1" onblur="change_quantity(this);" type="text" class="text w30 ipt-amount" data-stock="'+val.stock+'"/><a href="JavaScript:void(0);" onclick="add_quantity(this);" title="增加商品件数" class="add-substract-key tip addBtn">+</a></td><td class="w120"> <em class="xiaoji">'+parseFloat(val.money).toFixed(2)+'</em></td><td class="w80"><br /><a href="javascript:void(0)" onclick="drop_cart_item(1);">删除</a></td></tr>'
                       	 })
                       	 console.log(item);
                       	 cartList +='<tr><th colspan="20"><strong>店铺：<a href="http://beian.80wlkj.com/shop/index.php?act=show_store&op=index&store_id=1">'+item.shopsName+'</a></strong> <span member_id="1"></span></th></tr>'+goodsList+'<tr><td class="tr" colspan="20"><div class="ncc-store-account"><dl><dt>店铺合计：</dt><dd><em nc_type="eachStoreTotal">'+parseFloat(item.shopsMoney).toFixed(2)+'</em>元</dd></dl></div></td></tr>';
                       })
                       $('.ncc-table-style tbody').html(cartList);
                       $('.ncc-all-account #cartTotal').html(parseFloat(res.allMoney).toFixed(2));
                       $('.shop-list input').change(function(){
                       	var indexArr = [];
                       	var totalPrice = 0;
                       	_shopsInfo = [];
			            $('.ncc-table-style .shop-list').each(function(index,item){
			            	if(!$(item).find('input').attr('checked')){
			            		$('#selectAll').removeAttr("checked");
			            	}else{
			            		indexArr.push(index);
			            		totalPrice += Number($('.shop-list').eq(index).find('.xiaoji').html());
			            		$('#cartTotal').html(parseFloat(totalPrice).toFixed(2));
			            		_shopsInfo.push(_shopsList[0].shopGoods[index].goodsInfo);
			            		console.log(_shopsInfo);
			            		if(indexArr.length == $('.ncc-table-style .shop-list').length){
			            			$('#selectAll').prop("checked","checked");
			            		}
			            	}
			            })
		               })
                    }
                },
                error:function(res){
                    console.log(res.responseText);
                }
            });

	}
	function _init(){
		var url = 'http://192.168.0.120:8080/ymshoping/goodsCar?token='+storage.getStorage('token');
		 $.ajax({
                url:url,
                dataType:'jsonp',
                jsonp:'callback',//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
                jsonpCallback:"success_jsonpCallback",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
                contentType: 'application/json; charset=utf-8',
                success:function(res){
                    if(res.code == 0){
                       console.log(res);
                       var shopsList = res.shopsList;
                       var goodsList = '';
                       var cartList = '';
                       _shopsList = shopsList;
                       _shopsInfo = [];
                       shopsList.forEach(function(item,index){
                       	 item.shopGoods.forEach(function(val,idx){
                       	 	goodsList += '<tr class="shop-list" data-cartid="'+val.goodsCarId+'"><td><input type="checkbox" checked></td><td class="w60"><a href="" target="_blank" class="ncc-goods-thumb"><img src="http://192.168.0.120:8080/ymshoping/pic?picId='+val.picId+'"alt="'+val.goodsName+'" /></a></td><td class="tl"><dl class="ncc-goods-info"><dt><a href="http://beian.80wlkj.com/shop/index.php?act=goods&op=index&goods_id=52" target="_blank">'+val.goodsName+'</a></dt></dl></td><td class="w120"><em id="item1_price">'+parseFloat(val.mall).toFixed(2)+'</em></td><td class="w120 ws0"><a href="JavaScript:void(0);" onclick="decrease_quantity(this);" title="减少商品件数" class="add-substract-key tip minuBtn">-</a><input value="'+(val.amount || 1)+'" orig="1" changed="1" onblur="change_quantity(this);" type="text" class="text w30 ipt-amount" data-stock="'+val.stock+'"/><a href="JavaScript:void(0);" onclick="add_quantity(this);" title="增加商品件数" class="add-substract-key tip addBtn">+</a></td><td class="w120"> <em class="xiaoji">'+parseFloat(val.money).toFixed(2)+'</em></td><td class="w80"><br /><a href="javascript:void(0)" onclick="drop_cart_item(1);">删除</a></td></tr>'
                       	 });
                       	 cartList +='<tr><th colspan="20"><strong>店铺：<a href="http://beian.80wlkj.com/shop/index.php?act=show_store&op=index&store_id=1">'+item.shopsName+'</a></strong> <span member_id="1"></span></th></tr>'+goodsList+'<tr><td class="tr" colspan="20"><div class="ncc-store-account"><dl><dt>店铺合计：</dt><dd><em nc_type="eachStoreTotal">'+parseFloat(item.shopsMoney).toFixed(2)+'</em>元</dd></dl></div></td></tr>';
                       })
                       $('.ncc-table-style tbody').html(cartList);
                       $('.ncc-all-account #cartTotal').html(parseFloat(res.allMoney).toFixed(2));
                       _shopsList[0].shopGoods.forEach(function(item,index){
                       	_shopsInfo.push(item.goodsInfo);
                       })
                       
                       $('.shop-list input').change(function(){
                       	var that = this;
                       	var indexArr = [];
                       	var totalPrice = 0;
                       	_shopsInfo = [];
			            $('.ncc-table-style .shop-list').each(function(index,item){
			            	if(!$(item).find('input').attr('checked')){
			            		$('#selectAll').removeAttr("checked");
			            	}else{
			            		indexArr.push(index);
			            		totalPrice += Number($('.shop-list').eq(index).find('.xiaoji').html());
			            		$('#cartTotal').html(parseFloat(totalPrice).toFixed(2));
			            		_shopsInfo.push(_shopsList[0].shopGoods[index].goodsInfo);
			            		console.log(_shopsInfo);
			            		if(indexArr.length == $('.ncc-table-style .shop-list').length){
			            			$('#selectAll').prop("checked","checked");
			            		}
			            	}
			            })
		               })
                    }
                },
                error:function(res){
                    console.log(res.responseText);
                }
            });
	}
	function _submit(){
		_shopsInfo = JSON.stringify(_shopsInfo);
		 var url = 'http://192.168.0.120:8080/ymshoping/shopsPurchase?goodsInfo='+_shopsInfo+'&token='+storage.getStorage('token');
    $.ajax({
                url:url,
                dataType:'jsonp',
                jsonp:'callback',//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
                jsonpCallback:"success_jsonpCallback",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
                contentType: 'application/json; charset=utf-8',
                success:function(res){
                    if (res.code == 0) {
                        window.location.href = './confirm.html'
                    }
                },
                error:function(res){
                    console.log(res.responseText);
                }
            });
	}
</script>
</body>
</html>
